package com.mbigger.netty.ch6;

import java.util.List;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class FrameReplayingDecoder extends ReplayingDecoder<Void>{

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        log.info("FrameReplayingDecoder");
        byte header = in.readByte();
        if(header == 0x68) {
            // 读取head的值，例如6，说明body的长度是6个字节
            int length = in.readByte();
            // 读取6个长度的body
            out.add(in.readBytes(length));
        }
    }

}
